*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
* SET GLOBAL $PATHS
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
global root = "INSERT CUSTOMIZED PATH"
global source = "$root/code/calibrations/results/"
global data 	= "$root/data"
global data_out = "$root/data/processed/HealthProcess"
global figures	= "$root/figsandtabs"
global tables	= "$root/figsandtabs"
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


/* This dofile produces a number of different results --  tables and figures */

/* TABLES */

* sumstatswb.txt	Table: Summary Statistics: German Claims Panel Data, Panel a (Appendix)

* sumstatspb.txt	Table: Summary Statistics: German Claims Panel Data, Panel b (Appendix) 

* sumstatsw.txt		Table: Summary Statistics: Low-Deductible Plans; Appendix

* sumstatsp.txt		Table: Summary Statistics: Low-Deductible Plans; Appendix


/* FIGURES */

* agejoinb.pdf		Figure: Age Distribution of Initial Plan Inception (Appendix)

* histlamstar12.pdf Figure: Age Distribution of Initial Plan Inception (Appendix)


scalar agewide=5 /* Scalar for size of age bins */

/* Graph settings */

set scheme s1mono
graph set window fontface "Garamond"

global size size(large)
global ls labsize(medlarge)
global legs medlarge


use "${data}\raw\PKV\MainPKVSample.dta", clear
set more off


/* Occupation dummies */

gen employee=SOZ_AN
replace employee=0 if civserv==1

gen selfemp=max(SOZ_SE,SOZ_FRE)
replace selfemp=0 if civserv==1

/* Plan Categories */

gen top=(tkatn==3)
gen plus=(tkatn==2)
gen eco=(tkatn==1)

/* Descriptives: all */

global varsused alter female bjgutbg bjgpers employee selfemp civserv D_RZ D_LA

matrix sumstatw=J(1,5,1)


foreach var of varlist $varsused {
*qui su `var' if nvalid>0&starty<2009, detail

qui su `var' if firsty<2009&agegr~=., detail

matrix varcheck=r(mean),r(sd),r(min),r(max),r(N)
matrix sumstatw=sumstatw\varcheck
}

/* Table A1 */

matrix sumstatw=sumstatw[2...,1...]

matrix rownames sumstatw= "Age (in years)" "Female" "Policyholder since (years)" "Client since (years)" "Employee" "Self-Employed" "Civil Servant" "Health Risk Penalty" "Pre-Existing Condition Exempt"

estout matrix(sumstatw, fmt("1 3 1 1 3 3 3 3 3" "1 3 1 1 3 3 3 3 3" "1 1 1 1 1 1 1 1 1" "1 1 1 1 1 1 1 1 1" "%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc")) using "${tables}\sumstatswb.txt", collabels(,none) mlabels(,none) style(tex) replace

replace premarkup=prem if premarkup>prem
matrix sumstatp=J(1,5,1)

global varsused top plus eco prem premarkup deductible expenditure

foreach var of varlist $varsused {
*qui su `var' if nvalid>0&starty<2009, detail
qui su `var' if  firsty<2009&agegr~=., detail

matrix varcheck=r(mean),r(sd),r(min),r(max),r(N)
matrix sumstatp=sumstatp\varcheck
}

matrix sumstatp=sumstatp[2...,1...]

matrix rownames sumstatp= "TOP Plan" "PLUS Plan" "ECO Plan" "Annual premium (USD)" "Annual risk penalty (USD)" "Deductible   (USD)" "Total Claims (USD)"
estout matrix(sumstatp, fmt("3 3 3  %9.0fc %9.0fc %9.0fc %9.0fc" "3 3 3  %9.0fc %9.0fc %9.0fc %9.0fc" "1 1 1  %9.0fc %9.0fc %9.0fc %9.0fc"  "1 1 1  %9.0fc %9.0fc %9.0fc %9.0fc"  "%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc" )) using "${tables}\sumstatspb.txt", collabels(,none) mlabels(,none) style(tex) replace

/* Figure A2 */

gen agejoin=alter-bjgpers
replace agejoin=0 if agejoin<0
histogram agejoin  if  firsty<2009&agegr~=., xtitle("Age when joining company", $size) ytitle(, $size) width(1) xlabel(, $ls)  ylabel(, $ls)

graph export "${figures}\agejoinb.pdf", replace

/* Figure A10 */

twoway (histogram lambdastar0 if lambdastar0<10&anasamp==1, start(0) width(0.1) color(gs10)) (histogram lambdastar0 if lambdastar0<10&firsty<2009&agegr~=., start(0) width(0.1)  fcolor(none) lcolor(black)),   xtitle("ACG Score ({&lambda}{sub:t})", $size height(7)) ytitle(, $size) xlabel(, format(%9.0g) $ls) ylabel(, $ls) legend(ring(0) pos(1) size($legs) rows(2) order(2 "Main Sample" 1 "Low-Deductible Sample" ))

graph export "${figures}\histlamstar12.pdf",  replace



/* Only low-deductible plans */

foreach var of varlist $varsused {

qui su `var' if anasamp==1, detail

matrix varcheck=r(mean),r(sd),r(min),r(max),r(N)
matrix sumstatw=sumstatw\varcheck
}

/* Table A5 */

matrix sumstatw=sumstatw[2...,1...]

matrix rownames sumstatw= "Age (in years)" "Female" "Policyholder since (years)" "Client since (years)" "Employee" "Self-Employed" "Civil Servant" "Health Risk Penalty" "Pre-Existing Condition Exempt"

estout matrix(sumstatw, fmt("1 3 1 1 3 3 3 3 3" "1 3 1 1 3 3 3 3 3" "1 1 1 1 1 1 1 1 1" "1 1 1 1 1 1 1 1 1" "%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc")) using "${tables}\sumstatsw.txt", collabels(,none) mlabels(,none) style(tex) replace

replace premarkup=prem if premarkup>prem
matrix sumstatp=J(1,5,1)

global varsused top plus eco prem premarkup deductible expenditure

foreach var of varlist $varsused {

qui su `var' if  anasamp==1, detail

matrix varcheck=r(mean),r(sd),r(min),r(max),r(N)
matrix sumstatp=sumstatp\varcheck
}

matrix sumstatp=sumstatp[2...,1...]

matrix rownames sumstatp= "TOP Plan" "PLUS Plan" "ECO Plan" "Annual premium (USD)" "Annual risk penalty (USD)" "Deductible   (USD)" "Total Claims (USD)"
estout matrix(sumstatp, fmt("3 3 3  %9.0fc %9.0fc %9.0fc %9.0fc" "3 3 3  %9.0fc %9.0fc %9.0fc %9.0fc" "1 1 1  %9.0fc %9.0fc %9.0fc %9.0fc"  "1 1 1  %9.0fc %9.0fc %9.0fc %9.0fc"  "%9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc %9.0fc" )) using "${tables}\sumstatsp.txt", collabels(,none) mlabels(,none) style(tex) replace
